<template>
  <a-modal
    :maskClosable="false"
    :title="title"
    centered
    :width="800"
    v-model="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
  >
    <a-form :model="form">
      <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="标题">
        <a-input :disabled="type === 0" placeholder="请输入标题" v-model="form.title" />
      </a-form-item>
      <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="内容">
        <Ueditor v-model="form.content" editorId="joinRule" />
      </a-form-item>
    </a-form>
    <template slot="footer">
      <a-button @click="visible = false">取消</a-button>
      <a-button :disabled="type === 0" @click="handleSubmit" type="primary">确定</a-button>
    </template>
  </a-modal>
</template>
<script>
import { headquartersRuleEdit } from '@/api/system/system'
import Ueditor from '@/components/Ueditor'

export default {
  components: {
    Ueditor
  },
  data() {
    return {
      visible: false,
      labelCol: {
        xs: { span: 24 },
        sm: { span: 4 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 18 }
      },
      confirmLoading: false,
      title: '',
      type: '',
      form: {
        id: undefined,
        title: undefined,
        content: undefined
      }
    }
  },
  beforeCreate() {},
  created() {},
  methods: {
    open(obj) {
      this.title = obj.title
      this.type = obj.type
      Object.keys(this.form).forEach(k => {
        this.form[k] = obj.data[k]
      })
      this.visible = true
    },
    async handleSubmit(e) {
      let { code, msg } = await headquartersRuleEdit(this.form)
      this.$message[code === 0 ? 'success' : 'error'](msg)
      this.visible = false
      this.$emit('edit')
    }
  }
}
</script>
<style lang="less" scoped>
</style>
